package com.linkage.educloud.ah.util;

/**
 * Created by 周振 on 2017/6/9.
 */

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.linkage.educloud.ah.R;


/**
 * 图片加载帮助类
 */
public final class ImageLoader {


    private ImageLoader() {
        throw new RuntimeException("ImageLoader cannot be initialized!");
    }

    public static RequestOptions avatarOptions = new RequestOptions()
            .centerCrop()
            .placeholder(R.mipmap.ic_default_avatar)
            .error(R.mipmap.ic_default_avatar)
            .priority(Priority.HIGH)
            .circleCrop()
            .skipMemoryCache(true)//跳过内存缓存
            .diskCacheStrategy(DiskCacheStrategy.NONE);
    //    public static RequestOptions avatarOptionsC = new RequestOptions()
//            .centerCrop()
//            .placeholder(R.mipmap.ic_mine_avatar)
//            .error(R.mipmap.ic_mine_avatar)
//            .priority(Priority.HIGH)
//            .signature(new ObjectKey(System.currentTimeMillis()))//签名，默认签名，，解决同地址，头像更新问题，改变后，改变下签名
//            .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
    public static RequestOptions adsOptions = new RequestOptions()
            .placeholder(R.mipmap.backgrand_white)
            .error(R.mipmap.backgrand_white)
            .priority(Priority.NORMAL)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);

    public static RequestOptions imgOptions = new RequestOptions()
            .placeholder(R.mipmap.ic_not_found)
            .error(R.mipmap.ic_not_found)
            .priority(Priority.NORMAL)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);

    public static void loadAvatar(Context context, String url, ImageView view) {
        Glide.with(context).load(url)
                .apply(avatarOptions)
                .into(view);
    }

    public static void loadAvatar(Context context, String url, ImageView view, RequestOptions options) {
        Glide.with(context).load(url)
                .apply(options)
                .into(view);
    }

    public static void loadAds(Context context, String url, ImageView view) {
        Glide.with(context).load(url)
                .apply(adsOptions)
                .into(view);
    }

    public static void loadImg(Context context, String url, ImageView view) {
        Glide.with(context).load(url)
                .apply(imgOptions)
                .into(view);
    }
}

